package cn.com.headfree.dto;

import java.io.Serializable;
import java.util.List;

import com.gta.edu.sdk.util.StringUtil;

public class MenuDto implements Serializable,Comparable<MenuDto>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String id;
	private String url;
	private String name;
	private String type;
	private String parentId;
	private String seqNumber;
	private List<MenuDto> children;
	private String pathId;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<MenuDto> getChildren() {
		return children;
	}

	public void setChildren(List<MenuDto> children) {
		this.children = children;
	}
	
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj != null) {
			if (obj instanceof MenuDto) {
				MenuDto dto = (MenuDto)obj;
				if (this.getId().equals(dto.getId())) {
					return true;
				}
			}
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return this.id.hashCode();
	}

	@Override
	public int compareTo(MenuDto dto) {
		if (!StringUtil.isNullOrEmpty(dto.getSeqNumber()) && !StringUtil.isNullOrEmpty(this.getSeqNumber())) {
			if (this.isNumber(dto.getSeqNumber()) && this.isNumber(this.getSeqNumber())) {
				int thisNum = Integer.parseInt(this.seqNumber);
				int dtoNum = Integer.parseInt(dto.getSeqNumber());
				return thisNum - dtoNum;
			}
		}
		return 0;
	}
	
	private boolean isNumber(String str) {
		char ch;
		for (int i=0;i<str.length();i++) {
			ch = str.charAt(i);
			if (!Character.isDigit(ch)) {
				return false;
			}
		}
		return true;
	}

	public String getSeqNumber() {
		return seqNumber;
	}

	public void setSeqNumber(String seqNumber) {
		if (StringUtil.isNullOrEmpty(seqNumber)) {
			this.seqNumber = "0";
		} else {
			this.seqNumber = seqNumber;
		}
	}

	public String getPathId() {
		return pathId;
	}

	public void setPathId(String pathId) {
		this.pathId = pathId;
	}
}
